/**
 * API接口封装
 * @Author: Abdusalam0126 2383624944@qq.com
 * @Date: 2025-08-05 15:46:19
 * @LastEditors: Abdusalam0126 2383624944@qq.com
 * @LastEditTime: 2025-08-05 16:03:13
 * @FilePath: src/utils/api.ts
 * @Description: API接口封装
 */

import http from './http'

// 用户相关接口
export const userApi = {
  // 微信登录
  wechatLogin(code: string) {
    return http.post<{ token: string; user_id: number; user_info: any }>('/user/auth/wechat/login', { code })
  },

  // 获取用户信息
  getUserInfo() {
    return http.get<any>('/user/info')
  },

  // 获取用户资料
  getUserProfile(userId: number) {
    return http.get<any>(`/user/profile/${userId}`)
  },

  // 更新用户资料
  updateUserProfile(userId: number, data: any) {
    return http.put<any>(`/user/profile/${userId}`, data)
  },

  // 上传头像
  uploadAvatar(userId: number, filePath: string) {
    return http.upload<{ avatar_url: string }>(`/user/profile/${userId}/avatar`, filePath)
  }
}

// 字母学习相关接口
export const harpApi = {
  // 获取字母列表
  getHarpList() {
    return http.get<any>('/harp/list')
  },

  // 获取字母详情
  getHarpDetail(id: number) {
    return http.get<any>(`/harp/detail/${id}`)
  }
}

// 词汇学习相关接口
export const sozlukApi = {
  // 获取词汇列表
  getSozlukList() {
    return http.get<any>('/sozluk/list')
  },

  // 获取词汇详情
  getSozlukDetail(id: number) {
    return http.get<any>(`/sozluk/detail/${id}`)
  }
}

// 学习记录相关接口
export const learningApi = {
  // 记录学习进度
  recordProgress(data: any) {
    return http.post<any>('/learning/record', data)
  },

  // 获取学习历史
  getLearningHistory() {
    return http.get<any>('/learning/history')
  },

  // 获取学习统计
  getLearningStats() {
    return http.get<any>('/learning/stats')
  }
}

// 搜索相关接口
export const searchApi = {
  // 搜索内容
  search(keyword: string) {
    return http.get<any>('/search', { keyword })
  }
}

export default {
  userApi,
  harpApi,
  sozlukApi,
  learningApi,
  searchApi
}